#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
const int N = 1003;

int dp[N][N];
int main() {
    vector<string> v1, v2;
    string s1, s2;
    cin >> s1 >> s2;
    string now;
    for (char x : s1) {
        if (x >= 'A' && x <= 'Z') {
            if (!now.empty()) {
                v1.emplace_back(now);
            }
            now = x;
        } else {
            now += x;
        }
    }
    v1.emplace_back(now);
    now.clear();
    for (char x : s2) {
        if (x >= 'A' && x <= 'Z') {
            if (!now.empty()) {
                v2.emplace_back(now);
            }
            now = x;
        } else {
            now += x;
        }
    }
    v2.emplace_back(now);
    now.clear();

    int n = v1.size(), m = v2.size();

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (v1[i - 1] == v2[j - 1])
                dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
            else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}